package com.csi.sai.bl.viewfilters;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.sql.DataSource;

import com.csi.sai.data.entities.GenericFilters;
import com.csi.sai.utilities.Constants;
import com.csi.sai.utilities.Utilities;
import com.csi.sai.utilities.templates.selects.ComponentTemplate;

public class ViewFiltersProcess {
	
	private DataSource ds;
	private String HTMLCode;
	
	public String getHTMLCode(){ return this.HTMLCode; }
	
	public ViewFiltersProcess(DataSource ds) {
		this.ds = ds;
	}
	
	public boolean getDinamicFiltersBy(int type, GenericFilters gFilters, ComponentTemplate gComponent) { 
		Connection conn = null;
		ResultSet rs = null;
		PreparedStatement ps = null;
		
		try {
			conn = ds.getConnection();
			ps = conn.prepareStatement(Constants.CALL_PROCEDURE_DINAMICFILTERS);
			ps.setString(1, "solicitud");
			ps.setInt(2, type);
			ps.setInt(3, gFilters.getIdCliente());
			ps.setInt(4, gFilters.getIdEmpleado());
			
			rs = ps.executeQuery();
			gComponent.setRS(rs);
			
			HTMLCode = gComponent.getComponentGeneric();
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			Utilities.finallyProcess(conn, ps, rs);
			Utilities.finallyConnection(conn);
		}
		return false;
	}

}
